added more debug info and used it to fix some bugs