error corrected and added comments