Misc patches

Just deploying beam out to a number of our projects and have ran into a number of things which I've patched to our local version of beam. The commits attached are left separate to make it easier to review.