main, logic