implemented main logic