Cleaned up the type checking code a bit.