Refactoring (not finished all but compiles yet)