Move main into function. Only import ContourWriter if debugging is
turned on