New controller logic

Please read it before merging!!