refactoring code to support mri and jruby