Refactored according to code-review.