finished, not verified yet
refactorings, major bugfix: terminating now