Fixed most of the type errors, a few more to go.