MASSIVE CODE CLEANUP: Changed database to make it more abstract, cleaned up lots of duplicated code, probably broke a lot of things.