Bugfix and unit test