made function getLinks and simpler main function