Added error checking codes