fix issue of order of operations