more bugfixing and debugging