Bunch of refactoring