Major library re-organization
Minor changes and bugfixes