Setting up PQueue to do proper locking by some minor refactoring