Add emitOnce function, fix error in regular emit code