fix'd alrogithm (maybe?)