Fix another bug introduced by 6e7e042

Added a regression test as well.