Add error checking for ranges, fix a typo