Refactor change detection

WIP
Done.