Separated some functionality out into external files.