Fixes bug introduced in the previous commit. Includes test.