bug fixes, refactored code.. more debugging remains.
more diagnostic logs and bug fixes.