bugfixing and cleanup