More type fixes and cleanup