Changes to algorithm, still not working