Fixes #2 and fixes from https://github.com/Baystation12