Started moving code out of main.py. Will need better structure.