fixed major algorithm mistake