Some funciton rearranging.