refactoring the code....