refactored code and functionality