Increase error checking to avoid exceptions