Fixed Issue #9. Needs testing