bugfixing and added some debug messages