Modified algorithm for extracting context to be more robust.  Added multiple tests for testing context extraction.