Fix shadowing of err and added testcases