Pull altf4's improvements in

Good changes @altf4 , I was going to fix one or two of these bugs and then noticed you've been working on them already. Thanks for contributing!