separation to packages, minor refactoring