remove code duplication
Codingstyle fixes
Codingstyle fixes
Merge pull request #4 from mjrider/fixes

logic deduplication and coding style fixes