Added error checking code.