changed some error handlings