Writing search functionality