separate some logic in saveData method