Got rid of duplicated code. Invalid syntax error on line 47?