Rewrite config loader and add tests