fix some logical errors in if clause