main logic implemented