Some cleanup and counting added