changed some error handling