refactored and design improvements