some logic improvements