a bit refactoring and added tests for new controller