Controller work and some refactoring