added iterative selection algorithm and added more unit tests