added first two traverse if blocks