Fixed some performance issues and issue with theme switching redirect