further refactor of controller