Added some typechecking
merged