Added typechecking, several tests.