Refactoring and Add test code : sqlite group function