revised insert method