added typechecking to make sure return value is present