refactored much for modular usage