Wrote some extremely garbage code that was at least correct, then immediately reworked it into something at least slightly less trash, but for whatever reason today I needed to write the worse version before I could get my head to spit out something a little more reasonable.