Fix bug in ESA, other cleanup.