fixed more error handling