adding debug printouts to track problems
several fixes
fixed crashes, runs but does not yet produce correct result