Improved the heading margin handling