By Owen Gallagher, available on GitHub