update script to account for edge cases