Library refactor

Minor style and flow refactoring
Place else on same line as ending if bracket
Merge pull request #1 from nlefler/master

Library refactor