extracted logic from save_to_db method into private methods