Refactor controller and clean up