Moved logic from routes to controllers.