Added module credit as this has turned into a rewrite ;)