Merge "Fix bugs in auto restriction." into pi-dev