General cleanup

needs a medium-sized refactoring pending more structural changes