extensive refactor + enhancements