Fix spelling
Extract utility functions and constants

Makes for a more readable overall structure.