refactored main.py

Didn't know much Python when I wrote this.