Refactor function for finding text in table