Added multiple error checkings and better tokenising.