Made some big fixes while trying to get rid of compiler errors.