Ported to ruby 2.1.3