updated error function
added comments