code structure refactored