Mostly refactoring

Separate single stats function into separate functions for top 10, bottom 10 and history. Use package level var for the postgres connection string. Split code into multiple files.