Regarding James Lawrie, I spent days trying to untangle the realtionships. It seems certain that he and Margaret Philp were childless, but they appear to have raised Thomas Mathewson from infancy. Thomas was the son of Thomas Mathewson and Ann Pitillo and was born around 1819. Ann Pittillo was a daughter of George Pitillo. We find George in 1841 living next door to Margaret (Anderson) Lawrie, widow of John Lawrie, James' brother. I can only guess that Ann Pitillo died when Thomas was still young, husband Thomas having predeceased her, (only one child was recorded) and that James and Margaret took the child in. He certainly lived with them right up to his relatively early death in 1869. He had never married.
Ann Pitillo was an aunt of Grace Pitillo who married Alexander Henderson. Alexander (my great-great grandfather) was a nephew of the George Henderson who married Catherine Lawrie.
James married Martha Gray after Margaret Philp died. Whether or not this was a menage a trois we shall never know but Martha's own story is also intriguing. Her grandmother was Martha Philp, sister of the David Philp who married Mary Langlands so James' first wife, Margaret, was Martha's second cousin. Martha had a child, William Young Nimlocks, to a John Nimlocks, in 1838. He was known throughout his life as William Young, however, and no father was named on his death registration. Did Martha simply make up the name of John Nimlocks? William was brought up by Martha and James (and Margaret) and lived with them till his death from TB in 1861, not long after James and Martha married. The bombshell discovery, however, was the appearance of Andrew Thomson Lawrie in 1861 at the age of 20. It is clear he was acknowledged as James and Martha's son, but there is no record of birth and I cannot find him in any census before 1861. He remains a mystery to me. (Was Margaret prepared to accept Martha's illegitimate son by another man but not one by her husnand Why was this child named Andrew Thomson? oes this point to his foster parents? Why was he be born in Dunfermline?)
All in all, this could make a plot line for any soap opera.