Added some error checking to variables