Initial source code (that worked well enough for my purposes)