Refactoring (almost done)