Added some value checks to prevent errors