Master.issue3

Refactoring and optimizations leading to next version. Completely backwards compatible.