correcting length checks for objects and added some debug code