renamed err var which was shadowing previous var