Fix notices and using not-defined variables