Added support for mutlibyte remaining lenght.  Moved more complex macros to functions.