Refactored the structure and cleaned up code.
Also reduce the indentation length