Fixed a few bugs which were discovered after testing on the real hardware.