Splitting stuff into smaller methods to make profiling easier.