Changed BasedeviceAgent and refactored code where needed