factored out the modified mod6