better encoding for different ruby versions