added error handeling and retry