Move things around, trying to factor utilities out

This is more maintainable, moving utility functions to a separate,
hidden module.