Added error return code handling