Added debug menu option and started tidying up 'window' handling