fixes #703

Since the original author didn't make a pull request, I made one with the original code