Better closing of scanner