move most document change functionality into the correct directive