Implementation and cleanup of execute function, and a number of other cleanup items.