fix margin calculation problem