fix complete program break by adding null check

My bad, I forgot to at least run the code before committing and pushing
it