updated error function to return string instead of just echoing