For #6 fixed some unused code and duplicated code