restored old type system, merged in some useful functions