Extract parts of main.c into different files.
Remove exiting with normal mode esc.