Refactored string maximum length checks.

Added some string argument checks.

Moved some memory allocation of strings to the stack.