Major updates to search function. It is almost finished now.