Add  addedBefore and addedAfter handlers

work in progress. Tests will be written before merge, use at your own peril.