make main logic less convoluted