refactor, bugfixes