Main function added, which should make it easier to separate the various tasks