Complete refactor and basic testing of models and controllers