added error protection