refactored factorization of powers of two