Added some checks to fail gracefully