Added history search logic