Extract code from long function