refactoring; tests added, some variable and classes renamed etc.