Adding simple connection pool support
Small refactor on query scope and adding counting support