Fixing margin calculations