fixed algorithmic mistake