Some bugs fixed and Bluetooth code added (within comments)