refactoring the existing code