reorganized code, more features and bugfixes