added some safety exception checks