First attempt to modularize the script