Code clean up and better error handling for systems without tray support