added countLinks function