Initial version modified by @samueljon