Check first links instead of last links

uses pop(0) instead of pop(). Needs further refinement