Updated with small changes after code review.