initial fixes and some debugging