Sorry, I just realized that there are many things wrong with this pull request. I'll close it and take another stab at it later.