s4-ldb: don't remove a message element beyond the end of the array