fixed some error handling