Lots of refactoring. Added some comments and fits MVC now