implements some  generic functions and saveOnEntry function