main logic structure