refactor ESA creation
fixes two possible memory leaks