Correct fix for undefined object error