Make the program more modular and extensible

This is just the first step. There's still a lot to do.