Took out some repeated code

Could probably reduce amount of code for searching for SELECT keyword and then searching for ) character.