fixing issues with the context calculation (amongst other fixes #197)