merge bugfix and tests from refactor branch