Extract logic to controller