Fixed typo and added some sanity checks