improve error handlings