Refactor string functions, fix many defects.

Okay, I personally think they help to clarify what you actually intended and remove the risk of typos (like dangling else etc).