restructuring and bugfixing