String matching algorithm and grabbing stuff from the database