Fixes to issue #40, issuse #27 and issue #10