Correct most of the unsigned vs. signed warnings (or int vs. size_t), and rename some local variables to avoid name shadowing.