Refactor controllers

some error handling included