Code refactoring issue