add tests for contour.go and fix some bugs