Refactored main() a bit