Some important fixes from @chickeaterbanana's fork

These commits do not include unit tests, examples, JSON support, or GDC specific fixes. They are still in @chickeaterbanana's fork.