Separated routes and added better handling of errors