Some fixes

Split up into individual commits, each with explanation.