Fix error handling
Fix code style and doc style