bugfixing and cleaning up