I just realized tbeck already posted a solution to the problem. Excellent.