Battery Management Algorithm for Electric Vehicles