Peg selection logic revised (see code notation for details)