Refactored code

Preparing to switch to https://github.com/tres-framework/Trestle.