Added error checking.