Better implementation for insert