Code cleanup.

Full tested and does not break and old tests.