Changed if(typeof var === undefined) to if(var). Made errors error objects.