Rewrote the script entirely and changed the structure to verify first and then make changes as needed.
Logs according to a single file
TODO: Need to put in some verification if the parameters are missing but otherwise usable as is.