Refactored code according to pull request.