You can NOT directly edit an ESM files. That is why it is a Master. You instead have to record changes with an ESP file, and when the game loads, it goes down the list, loading the masters first, that applying the changes of any ESPs.
If you want to fix bugs in mods, then set the mod as the active file and make the changes directly to it. If you want to change something in an ESM, then you HAVE TO do it through an ESP.
Well, technically you could turn the ESM into an ESP and then convert back, but that is very risky, because any error and you will have to reinstall the game. With an ESP, any error is solved by removing the mod.