do same as befoure, but do all calculations mod 13