Reworked theme handling code