proper error handling of undefined variables