A first working implementation of the main script