Replace chunk of unnecessary code with gmatch

self-explanatory