Code refactoring using methods