Better cleanup, corrections

Provides a termination hook for the EntityManager which cleans up all
loaded entities after the runtime terminates.  This hook is *not* called
if an error has unexpectedly terminated the runtime.

This commit also provides the correct code for the deserialization of
Listener components.