code cleanup php stage 4 (almost final)