Implemented main logic