Added a check for valid id's in the link function