refactoring using modules, minor fixes