fix npe and some coding style