reuse err variable

don't see why to have more as one error variable in memory
there is a better way
add error handling