Fix notices and using not-defined variables

is the indentation on this wrong?