Restructured the whole thing
Added proper comments