Ported over framework from P2