fixes some bug on wrap region and change some nil to 0