Added ESM Function and fixed several minior issues