implemented some suggestions from steven
corrected some debug codesnips