fixed a bunch of defines and tweaked code to actually compile
long ago i added stuff, deleted trailing whitespace