factorize toPBM a bit