Derp.
The code does exactly what I asked it to do. Oops.