+ option to force encoding (false by default)
+ encode_if_needed is no longer a method call (to avoid the repeated method lookup)
+ remove redundant to_s calls
+ remove unnecessary nil check