Refactor to move logic into controller

Panel logic moved from HTML to controller