cleanup

minor restructuring, small bugfix here and there