Placed some code outside the main script as external functions. Trying to use chunks to make it easier to test code