Lots of improvments.
Add logging.
Merge