Clarified flow of algorithm