bugfixes, refactoring, i improvements