More intelligent implementation of insert