restructured script to have more readable design and a more verbose, structured output