Added bottomMargin calculation for defragGrid().