slightly more robust primitive cell algorithm
Automatic Py3k merge for testing