cleanup and refactor for controller