Sorting data and saving it into database!