Reorganize code

Separated HTML from PHP functions.