modified script to account for optional arguments