main controller logic