Main: move the php functions out of the html, replace them with echos of rendered variables.