Added form and URL validation, moved the DB query logic outside of the route files