Changed algorithm to incooporate all data.