Added error function. Will add error function to the rest of the code.