Correcting a stupid error where I check for NULL at the wrong time