Cleaned the code and added documentations