Fixing the invalid context exception