Refactoring with new code structure