Initial Re-write

I decided to rewrite the entire engine. It was pretty tangled and messy
before, and now it should be more independent and clean.