Move threshold check inside file loop so it only closes enough to get back under threshold
Put defaults back in place
Some style fixes