Refactored OSX battery code