Improvements according to code review 4-5.
Work in progress.

Rewrite according Daniels 4-5 review.