refactored main panel code to remove circular dependencies