think i've fixed the error handling