Refactored insert method