Comments added and duplicate code removed