Added some checks to allow the script to run with no parameters