better calculation for margin