Fix for Issue 31

The commits relevant to Issue 31 are b1c4205, d38218d, 86fc80b, b3ee4a1, e22cc5a. 

There are other bugfixes, here, too. But you may or may not be interested in those.