Parts library refactoring and bugfixes

This commit orignally consisted of 8 patches
Un-squased commits are at https://github.com/hriesz/oregano