Handling of non periodic distances too