Breaking up a large function