added comments and cleaned up the php code in index.php