Added directive and refactor controller