Revert last change because it was badly designed and introduced some bugs