Battery bugfix: Battery state not updated. Little clean-up of code.