Avoid invalid memory access when processing dimensions
Free memory allocated for step and block stats
Clean up memory leaks from the write group structure