code seems to produce perfect output for link state