implemented main logic and its testing