error-checking and var fixing