Begin fixing of control flow. Not 100% correct atm but getting there