added full error handling