first draft for the main logic