Cleaned up the PHP and reduced cycles needed to complete