counter works and is slightly optimize but not ideal