refactored functions and module structure.