add invert option and fix dict order bug