Fixed regression introduced by previous commit and added a test to prevent future regressions.
Merge branch 'performance_fixes' into moar-faster