Added better functionality to error function