fix partitionId detection; general optimizations