change variable name to avoid weird infinite loop

and restore checking for necessary attributes