Massive code Refactoring