bugfix & refactor