refactorization & bugfixing, close #10, progress made in #5, #15, #3, #8, #11, #12