Really fix control_lib.sh. :/
Reshuffle code a bit to prepare for some major refactors.