Implemented a few further suggestions by @mdboom