Tweak pedz code to work in rails