Fixed getContext method to prevent null values