Fix bugs found in hardware testing