Tidied up and copied from ywecurs repo. All is well