Refactoring array_to_bytestr to make it cleaner.