Ported to Ruby 1.9