Improved robustness by inserting error checking