fixed error, worked on making code slightly more DRY