Added controller component and code refactoring