added missing if
cleanup
added new variable