corrected and added comments