bugfix and tests