Refactor theme system
Fix exception on shutdown
Improve error handling during shutdown