Restructing code and adding json support for the configuration