Refactor a bit and correct to run on Ruby 2.0.0-p247 without warnings