refactoring the code..