The original implementation is actually by Sam Stephenson, so let's credit him instead of me here.