Creating generic search function that takes a block