refactoring, moved to TCHAR totally, fixed formatting and comments