cleaned up algorithm.
fleshed out more testing cases
moved typecheck error from inst.go to type.go