modify Q1.5 to match book algorithm