Restructure and deletion of unneeded php code