#1 retested on ruby 1.8.7 and 2.0.0. Done necessary amendments