Pull logic out and abstract for PE builds