1.0.x rebase

1.0.x rebased to include all commits on master. Some code reworked so all the tests now pass.