refactor + bugfix