Fix margin calculation