bugfix + refactoring + debug