added debug flags/printouts (see .ion) and other bugfixes