Standardize callback and cleanup code.