Started cleanup of code introduced a bug at some point