simplifying how links are generated
correcting the bad variable check