added and applied error function