Handle corner cases

Consider possible errors.