Refactoring config

FINALLY merging this branch into master.