moved scan loop inside Try clause (error outside of clause).