Fix issue 99

Contains commit 09e4751a4aa3ddef6a5250187175049c8ed57a97 which is also part of pull request #174.