Resolves #35. Fixes loop issue, adds clone option.

Library diverged since original pull request was submitted. Thanks to Neil Rotstan (nrotstan) for the work. This was based off his changes.