lots of refactoring to rest controller