Adding some error checking