Updated mainLogic