refactoring to functional packages