Fixes issues 316 318 319, and part of 322. But unsure if it broke something else.