Added unused variable check, and then used it to remove some unused variables