Futher refactoring based on comments missed on pull request.