fixed egger's algorithm