This could use some comments on what exactly it's trying to accomplish. I suspect it could be done in a simpler fashion, but I'm having trouble actually identifying what the goal is in the first place.