Implemented insert function.