Fixed errors in context. Added corresponding unit tests.