bugfix + corresponding tests