Cleanup and error checking for variables.