fixed some error handlings