rewrite a bunch of stuff, enable this thing to compile on Linux so I can valgrind/debug it