Fixing a bug in previous rewrite