changed some logic