More work on cleaning php and externalizing functions.