Fixed a few signed/unsigned comparison warnings, removed repeated calls to strlen, and fixed ambiguous indentation.

Submitted as a single commit because the code in both files is almost identical.