Added changes based on stack overflow review.