Large cleanup and refactoring of unescape() function.