Tried to correct bugs in the location trim algorithm.