Major cleanup of main php file

Dead code removal, mostly.
Fix missing ul tag

What a mess; needs to be refactored.