Improvement based on @Eric89GXL's code review.