changed the script to account for different cases