Started out by coding up a couple of useful functions.