Code refactor for MVC

Created new classes and moved code to fit MVC pattern.