[Controllers] Refactoring and adding tests.