refactored the code.