reorganize code
bugfixes