complete refactor of logic from view to controller