refactor to move more logic into controller