Small program flow bugfixes