fixed formatting and error function