cleanup

Linted, styled, shortened long lines, added comments, separated out some functions, explicitly exposed functions.
Needs moar whitespace.