Changed add and search_nn into iterative functions