updated code from routes to controller