Rewrote search to be more effiencient