Modified some code that caused warnings, was ambiguous, and was inefficient

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.