simplify codes and throw instance of Error on syntax error