Fixes #370
This solution is uglier then the one in
6f497bb9fcef29c0c8707a81da6255d9ea49fff3, but it at least should always
work.