Pulled out some functionality into its own classes.

Now looking good in foundation 5.