Review and refactoring part 1

config is now json.
default layout is now always called 'default' and not anymore configurable.
fixing a race condition: checking for file existence before opening it is bad, just open it.
some useless blank lines removed.
some unnecessary local variables removed.