factor out code for generating tables of powers