Refactor config file handling

This also fixes #50