updated according to code review.