refactoring using extract method.