finalize search function