this could use more explanation into the error-handling that is going on.