bugfixing and clean up