Fixes #700

Tested and working. A lot more confident in the code than I am with my Github skills.