small cleanup
Refactored code. Restructured to follow MVC pattern.