This is a quick and dirty fix of issue #212. Partially reverts previous changes from commit 5fbd1f08c4 Re-implements the change in a slightly different way.
5fbd1f08c4