updated to support arbitrary line counter functions