optimize code
Fix bug with live-counting