Added video mode detection
Refactored main loop
Renamed some stuff