An improved immersed boundary method for curvilinear grids