Fixed many fatal errors

I made a lot of minor, miscellaneous fixes and can now install the module with no errors. It's not usable, but it can at least be enabled without breaking.