more refactors and enhancements