updated and refactored code.