Refactor main file, add command handlers

Restructured the main file into different code sections: entry point,
main loop, program functions, and procedures. The command handlers
belong under the program functions group.

Implemented support for "help" and "exit".