Reordered code and split out some functionality.