metaprogramming for theme, various fixes