Fixing some variables and adding try except