refactored bluetooth fixes from master. needs testing.
 code cleanup.