emproved algorithm