A compound of formula: or a pharmaceutically acceptable salt thereof; wherein W a 2 is CR 5 or N; W a 3 is CR 6 or N; W a 4 is CR 7 or N; wherein no more than two adjacent ring atoms selected from W a 2, W a 3, and W a 4 are heteroatoms; B is hydrogen, alkyl, amino, heteroalkyl, or a moiety of formula II: wherein W c is aryl, heteroaryl, heterocycloalkyl, or cycloalkyl, and q is an integer of 0, 1, 2, 3, or 4; X is absent or -(CH(R 9)) z -, and z is an integer of 1, 2, 3, or 4; Y is absent, -O-, -S-, -S(=O)-, -S(=O) 2 -, -C(=O)-, -C(=O)(CHR 9) z -, -N(R 9)-, -N(R 9)-C(=O)NH-, or -N(R 9)C(R 9) 2 -, and z is an integer of 1, 2, 3, or 4; R 1 is hydrogen, alkyl, alkenyl, alkynyl, alkoxy, amido, alkoxycarbonyl, sulfonamido, halo, cyano, or nitro; each R 2 is independently alkyl, alkenyl, alkynyl, cycloalkyl, heterocycloalkyl, aryl, heteroaryl, arylalkyl, heteroarylalkyl, alkoxy, amido, amino, acyl, acyloxy, alkoxycarbonyl, sulfonamido, halo, cyano, hydroxy, nitro, phosphate, urea, or carbonate; R 3 is a 5-membered heteroaryl, a 5-membered nonaromatic heterocycle, a 6-membered aryl, a 6-membered heteroaryl or a 6-membered nonaromatic heterocycle; wherein each of the above substituents can be substituted with 0, 1, 2, or 3 R 13; R 5, R 6, R 7, and R 8 are independently hydrogen, halo, cyano, alkyl or amino; each R 9 is independently hydrogen, alkyl, or heterocycloalkyl; W d is selected from the group consisting of R 11 is hydrogen, alkyl, halo, amino, amido, hydroxy, alkoxy, phosphate, urea, or carbonate; R 12 is hydrogen, alkyl, haloalkyl, alkynyl, alkenyl, halo, -C NH 2, aryl, heteroaryl, nonaromatic heterocyclyl, or cycloalkyl; R a' is hydrogen, alkyl, -NH 2, cyano, or halogen; or wherein W d is selected from the group consisting of R a' is hydrogen, halo, phosphate, urea, carbonate, amino, alkyl, alkenyl, alkynyl, cycloalkyl, heteroalkyl, or heterocycloalkyl; and R 12 is hydrogen, alkyl, cyano, alkynyl, alkenyl, halo, aryl, heteroaryl, heterocycloalkyl, cycloalkyl, amino, carboxylic acid, alkoxycarbonyl, amido, acyl, or sulfonamido; or wherein W d is R 12 is cyano; and each R 13 is independently hydrogen, C 1 -C 6 alkyl, C 1 -C 6 alkoxy, or halogen. W a 2 is CR 5 or N; W a 3 is CR 6 or N; W a 4 is CR 7 or N; wherein no more than two adjacent ring atoms selected from W a 2, W a 3, and W a 4 are heteroatoms; B is hydrogen, alkyl, amino, heteroalkyl, or a moiety of formula II: wherein W c is aryl, heteroaryl, heterocycloalkyl, or cycloalkyl, and q is an integer of 0, 1, 2, 3, or 4; wherein W c is aryl, heteroaryl, heterocycloalkyl, or cycloalkyl, and q is an integer of 0, 1, 2, 3, or 4; X is absent or -(CH(R 9)) z -, and z is an integer of 1, 2, 3, or 4; Y is absent, -O-, -S-, -S(=O)-, -S(=O) 2 -, -C(=O)-, -C(=O)(CHR 9) z -, -N(R 9)-, -N(R 9)-C(=O)NH-, or -N(R 9)C(R 9) 2 -, and z is an integer of 1, 2, 3, or 4; R 1 is hydrogen, alkyl, alkenyl, alkynyl, alkoxy, amido, alkoxycarbonyl, sulfonamido, halo, cyano, or nitro; each R 2 is independently alkyl, alkenyl, alkynyl, cycloalkyl, heterocycloalkyl, aryl, heteroaryl, arylalkyl, heteroarylalkyl, alkoxy, amido, amino, acyl, acyloxy, alkoxycarbonyl, sulfonamido, halo, cyano, hydroxy, nitro, phosphate, urea, or carbonate; R 3 is a 5-membered heteroaryl, a 5-membered nonaromatic heterocycle, a 6-membered aryl, a 6-membered heteroaryl or a 6-membered nonaromatic heterocycle; wherein each of the above substituents can be substituted with 0, 1, 2, or 3 R 13; R 5, R 6, R 7, and R 8 are independently hydrogen, halo, cyano, alkyl or amino; each R 9 is independently hydrogen, alkyl, or heterocycloalkyl; W d is selected from the group consisting of R 11 is hydrogen, alkyl, halo, amino, amido, hydroxy, alkoxy, phosphate, urea, or carbonate; R 12 is hydrogen, alkyl, haloalkyl, alkynyl, alkenyl, halo, -C NH 2, aryl, heteroaryl, nonaromatic heterocyclyl, or cycloalkyl; R a' is hydrogen, alkyl, -NH 2, cyano, or halogen; or wherein W d is selected from the group consisting of R a' is hydrogen, halo, phosphate, urea, carbonate, amino, alkyl, alkenyl, alkynyl, cycloalkyl, heteroalkyl, or heterocycloalkyl; and R 12 is hydrogen, alkyl, cyano, alkynyl, alkenyl, halo, aryl, heteroaryl, heterocycloalkyl, cycloalkyl, amino, carboxylic acid, alkoxycarbonyl, amido, acyl, or sulfonamido; or wherein W d is R 12 is cyano; and each R 13 is independently hydrogen, C 1 -C 6 alkyl, C 1 -C 6 alkoxy, or halogen.