Added error handling when  object isn't created correctly.