Move config and event handler into own modules.
Use optparse in main.