refactored more to main