code refactoring in bluetooth app