Third attempt at algorithm