Fix everything.

finally got all this !@#$ tested and working. this almost certainly doesn't compile on OSX, but unless someone wants to send me a Mac as a gift, I'm probably not going to be installing a hackintosh any time soon. @fricy?