Code refactoring for better practice