Cleanup function and variable mapping