Fixed connection selection in count()

The proper connection was not used in the count function
Merge pull request #83 from Jacq/master

Fixed connection selection in count()