Added logic to flush the score into database