modified some logic.