minor change in algorithm