simplified some logic