refactored bytes/unicode conversion