adding more error checking and tests