Fixing bug with calling method on undefined context object