Fixed several errors in the type inference and checking!!!