improve theme handling code