Broke main php file into includes.  Added comments and formatting.  Changed some input handling.