further cleanup of main logic