fixed bugs in P_OUT and P_IN