added lcresid function