Insert implementation, could be refactored.