Improve performance of config parser

The code is still not awesome, but it's much faster now.