Error checking and formatting