broke the count_dup function into pieces and added a test function