Modified the implementation after review.