Put stuff into functions to allow profiling