Tidied up main file so that it can run in console or Pygame mode