refactored back into main