refactored controller for RESTful routes