Partial merge of PR#4 plus additions/fixes.