All the hard work (apart from a small amount of testing) is by Brandon Palmer <bpalmer@crimelabs.net>