Refactor controllers, fix tests