functions used by the main script