implementation of insert method