Fixed 'err is undefined'