Changes to EM template and to various other bugs