Fix for issue #23

Seems to work for me but I am not familiar with the code at all.