refactoring controller and directive