move logic from routes to controllers