Fix import of P/T; misc optimizations