Adding updated script version from @liype