added comments on some duplicated code