Merge similar code patterns and add a test case for PSubscribe