fix dateline problem, and crash with inversions