Use code from ptools until PR is merged