Fixed regression introduced by previous commit and added a test to prevent future regressions.