Changes after review, code simplified.