replace crappy php code with proper explanation