Added debug messages; this version acutally compiles and does not crash