change the code according to Shahar's comments.