Refactoring, adherence to coding style, little optimization
Updated doc comments