changed time complexity of insert