Misc Refactor

Sorry for the non-descriptive message
Made function to get number of rows in DB table