add refactored code