Work

loads of type fixes, and a few more functions.