Refactor panel code to a class.