ADded Ruby implementation and refactored Python