Closes #2542. The actual flaw was identified by @reduz. Also fix a typo.
A general speedup should be apparent, with even more peformance increase when compiling optimized. WARNING: Tested and it seems to work, but if something breaks, please report.