added a new (better?) version of the main script