Support for Ruby 1.9 and string encoding

kconv has been replaced in Ruby 1.9, and with the changes to string encoding in Ruby 1.9, we had to make some changes to this to make it work properly with Ruby 1.