cleaned and written a simple error case handler