refactored the code..