Full Working Version of the PBE Script