Copied in bluetooth code from iOS Dev Library