Working on refactoring into MVC. Not completed.