Fixes a memory leak. Port to 0.5.
Check if grid.Lz >= max(thk). Port to 0.5.