Big refractor of setup logic