Fixed some defects in the contexts and added test coverage