Damian's fix for "attribute to NULL" error