added some logic to avoid uneeded updates