Refactored and reorganised code into MVC structure