major refactoring to decouple model from controller