simple tests, few discovered errors fixed, refactoring