Split the script - moved some of the functions to a dedicated file