removed duplicate code, and extraneous code