Move functional routines into main file.