rewrote search loops for better results