refactoring with compatibility with ruby (sans rails)