Changes to algorithm