removed loops in search function