refactored to better design