made the script accept parameters and added a debug option