Fixes and improved debugging.
Merge conflict fixed