Fixed context copy function