some code cleanup
controller structure and json error response #7
tests for prev commit #7