Don't refer to globals, use locals instead, and handle RTD_NEW_THEME = F...

...alse sanely