Added query and seperated handlers from routes