Fixing rare non-object error