move logic from routes to controller