refactored controllers and models to use phpdoc convention as well as move common code to model functions