Changed a few faulty if statements:

changed if(!var) to if(var == "")
Added a few comments.