Finish code refactoring (almost...)