More distributed debug

Fixes a serious bug in partitionLociUniformly that could cause an infinite loop. Scattered optimizations and improvements.