Cleanups and move dependency logic into existing loop in main.cpp