Added debug panel

Other minor rearrangements