Add power supply switching, and do some cleanup