Updated to use when and removed selection stuff after insert