Fixed a bunch of runtime errors