Make some variables local, and refactor fingerprint call when creating the public derivation (also fixes a bug from previous commit).