Modularized code a bit.