refactor main.py, flesh out functions from main function