Added error checking mechanism