Bugfix to tests and implementation