removed diff, simplified algorithm