Fix crash bug when bad values are passed into function.