fix the problem in computing margin