Function chopping

Started chopping up the big function in some smaller ones