Added some error handlings