batter memory handling,bugfix