Break up functions

Break up the functions a bit so we can spec in seperate files and make it a little more manageable.