Error checking and a tiny bit of input sanitization