Corrected a mistake with shared code

I didn't change the error handling when I factored some code out