replace python implementation with ruby