Rebuild replacement logic.
Update comments.