moved from html to native php, refactored code