MINOR: Style fixes and reduce code duplication