added debugging infrastructure
improved debugging infra
fixed bugs