improvements to main logic