modified some logic