Most of controller functions moved to models, code was cleaned up and documented