Update main.py

fixed various bugs and increased functionality