Refactored panel code into directives.