Fix issue 98. Not sure it's working perfectly and it's kinda ugly but
seems to do the job in simple tests.