refactor bugfixes