Moving logic to controller