Implementation of insert.