fixed type in comment
(cherry-picked from d46eb2d)
minor refactorings
(cherry-picked from a685914)