Make panel script more robust