Added error checking functionality.